﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.Xpo;
using DevExpress.Data.Filtering;

namespace POI.eTransmittal.Enitity
{
   public class OutgoingTransmittal:XPCustomObject
    {
       public const string DRAFT = "Draft";
       public const string WAIT = "Waiting";
       public const string SENT = "Sent";
       [Key(true)]
       public int ID;
       public string Subject;
       public string Author;
       public string To;
       public string FaxNo;
       public string Attn;
       public string RefNo;
       public string OriginalFileName;
       public string FaxFileLink;
       public string Remarks;
       public string Status;
       public string DocTypeCode;

       public string DocTypeName
       {
           get
           {
               DocumentType docType = Session.FindObject<DocumentType>(CriteriaOperator.Parse("Code=?", DocTypeCode));

               return docType.TypeName;
           }
       }

       public string Destination
       {
           get
           {
               return String.Format("{0} ({1})", To, FaxNo);
           }
       }

       public string UNC_LINK
       {
           get
           {
               return GetUNC_FileLink();
           }
       }
       public string GetUNC_FileLink()
       {
           if (!string.IsNullOrEmpty(FaxFileLink))
           {
               string uncPath = FaxFileLink.Replace("\\", "/");
               return "file://" + uncPath;
           }
           return null;
       }
       #region AuditTrail

       public DateTime CreatedDate;

       public string CreatedBy;

       public DateTime LastChangedDate;

       public string LastChangedBy;

       public void Save(string userId)
       {
           if (CreatedBy == null || CreatedDate == DateTime.MinValue)
           {
               this.CreatedDate = DateTime.Now;
               this.CreatedBy = userId;
           }

           this.LastChangedDate = DateTime.Now;
           this.LastChangedBy = userId;

           this.Save();
       }

       #endregion
       public OutgoingTransmittal(Session session)
           : base(session)
       {

       }


       public string GetFileName(string ext)
       {
           string first = "TI";
           string second = CreatedDate.ToString("yyMM");
           string three = ID.ToString();
           return string.Format("{0}-{1}-{2}{3}", first, second, three, ext);
       }
    }
}
